Skip to content

feat: add browser routing cache#99

Merged
rgarcia merged 19 commits intonextfrom
raf/browser-scoped-client
Apr 24, 2026
Merged

feat: add browser routing cache#99
rgarcia merged 19 commits intonextfrom
raf/browser-scoped-client

Conversation

@rgarcia
Copy link
Copy Markdown
Contributor

@rgarcia rgarcia commented Apr 13, 2026

Summary

  • remove the public browserRouting client constructor config and move rollout control to KERNEL_BROWSER_ROUTING_SUBRESOURCES
  • default direct-to-VM request interception to curl when the env var is unset, and treat an explicit empty string as disabling browser subresource routing
  • keep BrowserRouteCache public for debugging while making the routing fetch wrapper fully internal to the client constructor and withOptions()
  • keep browsers.fetch() cache-backed so raw HTTP continues to go directly to the browser VM’s /curl/raw path with no control-plane fallback

Rollout behavior

  • env var unset: route only curl subresources directly to the browser VM
  • env var set to "": disable browser subresource routing entirely
  • env var set to a comma-separated list: route exactly those subresources directly to the browser VM
  • browsers.fetch() still always goes direct to the browser VM because it resolves through the shared browser route cache and /curl/raw

Test plan

  • ./node_modules/.bin/jest tests/lib/browser-routing.test.ts
  • ./node_modules/.bin/eslint src/client.ts src/lib/browser-routing.ts src/index.ts tests/lib/browser-routing.test.ts examples/browser-routing.ts
  • ./node_modules/.bin/tsc -p tsconfig.json --noEmit
  • KERNEL_API_KEY=... KERNEL_BASE_URL=https://api.onkernel.com ./node_modules/.bin/ts-node examples/browser-routing.ts

Note

Medium Risk
Adds a fetch wrapper that transparently rewrites some /browsers/:id/* API calls to hit per-session VM base_url with JWT injection, which could change request routing/headers in production if misconfigured. Behavior is gated by env var allowlisting and includes cache eviction logic tied to delete/release flows.

Overview
Introduces a public BrowserRouteCache and an internal createRoutingFetch wrapper that sniffs browser (and browser-pool acquire) JSON responses to cache {session_id, base_url, jwt}, then conditionally rewrites allowlisted browser subresource requests to go directly to the browser VM (stripping Authorization and adding jwt as a query param).

Rollout is controlled via KERNEL_BROWSER_ROUTING_SUBRESOURCES (defaults to routing curl; empty string disables routing), and cached routes are evicted after successful browsers.deleteByID or browserPools.release. Adds browsers.fetch() implemented via /curl/raw using the shared cache (no control-plane fallback), exports BrowserFetchInit/BrowserRouteCache types, plus new tests and an example.

Reviewed by Cursor Bugbot for commit 81e47ca. Bugbot is set up for automated code reviews on this repo. Configure here.

@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR modifies client library code (browser session client) rather than API endpoints or Temporal workflows in packages/api/

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread src/lib/kernel-browser-session.ts Outdated
Comment thread src/lib/kernel-browser-session.ts Outdated
Comment thread src/lib/browser-transport.ts Outdated
rgarcia added 4 commits April 21, 2026 13:09
Bind browser subresource calls to a browser session's base_url and expose raw HTTP through fetch so metro-routed access feels like normal JavaScript networking.

Made-with: Cursor
Fail fast when browser-scoped clients do not have a session base_url, route subresource calls through the browser session base directly, and clean up browser-vm wording.

Made-with: Cursor
Fail fast when browser-scoped clients are missing a browser session base_url, route subresource calls through the session base consistently, and keep lint output clean.

Made-with: Cursor
Replace the handwritten Node browser-scoped façade with deterministic generated bindings from the browser resource graph, and enforce regeneration during lint and build.

Made-with: Cursor
@rgarcia rgarcia force-pushed the raf/browser-scoped-client branch from c5731cb to e730af8 Compare April 21, 2026 17:09
Comment thread examples/browser-scoped.ts Outdated
Route direct-to-VM browser requests through the shared client cache so the SDK no longer needs the generated browser session wrapper layer.

Made-with: Cursor
Comment thread src/lib/browser-routing.ts
Comment thread src/client.ts Outdated
Trim the node browser routing changes down to the cache/interceptor shape from PR #100 and remove the leftover browser-scoped example and priming surface.

Made-with: Cursor
@rgarcia rgarcia changed the title feat: add browser-scoped session client feat: add browser routing cache Apr 22, 2026
Comment thread src/lib/browser-routing.ts
rgarcia added 3 commits April 22, 2026 12:57
Shorten the browserRouting allowlist field to subresources so the direct-to-VM configuration reads more cleanly without changing behavior.

Made-with: Cursor
Keep the node browser-routing example showing both direct subresource routing and the cache-backed /curl/raw path.

Made-with: Cursor
Bring back the cache-backed browser fetch helper so raw HTTP stays on the SDK's language-native surface instead of falling through to manual /curl/raw requests.

Made-with: Cursor
Comment thread src/lib/browser-routing.ts
Comment thread src/lib/browser-transport.ts Outdated
rgarcia added 3 commits April 22, 2026 13:19
Remove the unnecessary generated resource and dependency diffs from the node branch and keep BrowserRouteCache.set() as a direct assignment without trimming user input.

Made-with: Cursor
Tighten the browser routing files to the repo's formatter expectations so the node CI lint job passes cleanly again.

Made-with: Cursor
Split browser.fetch into its own helper, remove unused browser transport code, and simplify withOptions cache sharing so the routing layer stays easier to reason about.

Made-with: Cursor
Comment thread src/lib/browser-fetch.ts Outdated
Comment thread src/lib/browser-fetch.ts
Remove the public browser routing constructor knobs and read direct-to-VM subresource rollout from KERNEL_BROWSER_ROUTING_SUBRESOURCES instead, defaulting to curl while leaving browser.fetch cache-backed.
Comment thread src/lib/browser-routing.ts
Keep the routing wrapper from stripping runtime-specific fetch init options when requests fall through or route directly to the VM, and share the browser fetch helpers so routed methods stay type-safe and covered by regression tests.

Made-with: Cursor
Comment thread src/lib/browser-routing.ts
rgarcia added 3 commits April 24, 2026 15:18
Only parse cloned JSON responses for browser metadata endpoints so unrelated API calls don't pay the route cache warm-up cost, and cover the regression with a focused routing fetch test.

Made-with: Cursor
Drop cached browser routing entries after successful DELETE /browsers/:id responses so stale base URLs are not reused, and cover both the success and failure paths in the routing tests.

Made-with: Cursor
Restore the generated internal types file so browser routing changes stay in custom code only.
Move joinURL into lib and keep browser.fetch limited to the SDK's existing HTTPMethod union.

Made-with: Cursor
Restore src/internal/types.ts byte-for-byte to the generated base version.
This drops the file from the PR so browser routing changes stay out of generated code.

Made-with: Cursor
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.

Reviewed by Cursor Bugbot for commit a7ff9bc. Configure here.

Comment thread src/lib/browser-routing.ts
Copy link
Copy Markdown
Contributor

@Sayan- Sayan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff - thanks for iterating on the shape!

Warm the browser route cache from browser pool acquire responses and evict released sessions after successful pool releases.
Keep this behavior in the routing middleware so generated resource methods stay untouched.

Made-with: Cursor
@rgarcia rgarcia merged commit e36b009 into next Apr 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants